﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TextToSpeach.Engine;
using System.Collections.ObjectModel;
using System.Speech.Synthesis;

namespace TextToSpeach
{
    public partial class formMain : ComponentFactory.Krypton.Toolkit.KryptonForm
    {
        private SapiEngine sapiEngine;
        public formMain()
        {
            InitializeComponent();
            sapiEngine = new SapiEngine();
        }

        private void formMain_Load(object sender, EventArgs e)
        {
            this.TextExtra = Application.ProductVersion;
            PopulateVoiceList();
            sapiEngine.Volume = 50;
            sapiEngine.Speed = -1;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void kryptonButton2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void kryptonButton3_Click(object sender, EventArgs e)
        {
            sapiEngine.StartSynthesis(kryptonComboBox1.Text, textBox1.Text);
        }

        public void PopulateVoiceList()
        {
            ReadOnlyCollection<InstalledVoice> voices = sapiEngine.GetInstalledVoices();

            try
            {
                VoiceInfo voiceInfo;
                foreach (InstalledVoice v in voices)
                {
                    voiceInfo = v.VoiceInfo;
                    kryptonComboBox1.Items.Add(voiceInfo.Name.ToString());
                }
                kryptonComboBox1.SelectedIndex = 0;
            }
            catch (Exception e)
            {
                MessageBox.Show("Unrecognized error: \n\t" + e.Message, "Text-To-Speach", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
        }

        private void kryptonNumericUpDownSpeed_ValueChanged(object sender, EventArgs e)
        {
            sapiEngine.Speed = (int)(kryptonNumericUpDownSpeed.Value);
        }

        private void kryptonNumericUpDownVolume_ValueChanged(object sender, EventArgs e)
        {
            sapiEngine.Volume = (int)(kryptonNumericUpDownVolume.Value);
        }
    }
}
